#!/bin/bash

LINE=$1

LOGDIR=/opt/mes/files/upload/log/sys/

# remove the old logfile
if [ ! -d $LOGDIR ]
then
    mkdir -p $LOGDIR
else
    rm -rf $LOGDIR
    mkdir -p $LOGDIR
fi

MOD="send xmljson board cfg dc filecmd graphdb machine mt oee real spc timedb plc"

for d in $MOD
do
    ID=`docker ps | grep $d: | awk '{print $1}'`
    if [ $ID ]
    then
        LOGFILE=$LOGDIR/$d.log

        exec 1>$LOGFILE 2>&1

        if [ $LINE ]
        then
            docker logs --tail $LINE $ID
        else
            docker logs $ID
        fi
    fi
done
